<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    /**
     * 方法1：使用split 
    */
    var url = "https://www.baidu.com/m?f=8&ie=utf-8&rsv_bp=1&tn=monline_3_dg&wd=session";
    function getURL(url) {
        let str =  url.split('?')[1];
        let params = str.split('&');
        let obj = {};
        params.forEach(item => {
            let key = item.split('=')[0];
            let value = item.split('=')[1];
            obj[key] = value;
        })
        return obj;
    }
    console.log(getURL(url));

    function solution(url) {
        let str = url.split('?')[1];
        const query = str.split('&&');
        let res = {};
        for (let str of query) {
            console.log(str);
        }
    }
    solution(url);

    /**
     * 方法2：使用正则表达式 + arguments
    */
    function queryURLparamsRegEs5(url) {
        let obj = {};
        let reg = /([^?=&]+)=([^?=&]+)/g;
        url.replace(reg, function() {
            // console.log(arguments);
            obj[arguments[1]] = arguments[2];
        })
        
        return obj;
    }
    var url2 = "https://www.baidu.com/m?f=8&ie=utf-8&rsv_bp=1&tn=monline_3_dg&wd=session";
    console.log(queryURLparamsRegEs5(url2));

    /**
     * 方法3：使用正则表达式 + ...args
    */
    function queryURLparamsRegEs6(url) {
        let obj = {};
        let reg = /([^?=&]+)=([^?=&]+)/g;
        url.replace(reg, (...args) => {
            // console.log(Object.prototype.toString.call(args));
            obj[args[1]] = args[2];
        })

        return obj;
    }
    var url3 = "https://www.baidu.com/m?f=8&ie=utf-8&rsv_bp=1&tn=monline_3_dg&wd=session";
    console.log(queryURLparamsRegEs6(url3));

</script>

</html>